﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using CS.model;
using CS.BLL;

namespace chaoshiguanli
{
    public partial class JieSuan : Form
    {
        public JieSuan()
        {
            InitializeComponent();
        }

        public List<BuyGoods> Buylist {get;set; }

        double totalMoney = 0.0;
        private void JieSuan_Load(object sender, EventArgs e)
        {
            foreach (BuyGoods item in Buylist)
            {
                totalMoney += item.XiaoJi;
            }
            txtshou.Text = totalMoney.ToString();
        }

        private void txtshi_KeyUp(object sender, KeyEventArgs e)
        {
            if (txtshi.Text != "")
            {
                txtzhao.Text = (double.Parse(txtshi.Text) - totalMoney).ToString();
            }
        }

        private void butjiesuan_Click(object sender, EventArgs e)
        {
            if (double.Parse(txtzhao.Text) < 0 )
            {
                MessageBox.Show("找零为负");
                txtshi.Focus();
            }
            else
            {
                BuyService or = new BuyService();
                bool ret=or.InsertOrder(Buylist, totalMoney, 1);
                if (ret == false)
                {
                    MessageBox.Show("订单生成失败，请重试");
                    return;
                }
                string mss = string.Format(@"结算信息：
实收金额：{0}
应收金额：{1}
找零：{2}",txtshi.Text,txtshou.Text,txtzhao.Text);
                MessageBox.Show(mss);
                Buylist.Clear();
                this.Close();
            }
        }

    }
}
